﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class user_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
    }
     
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        bool Authenticated = false;
        Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName,Login1.Password);
        e.Authenticated = Authenticated;
        if (Authenticated == true)
        {
            Response.Redirect("QueryNews1.aspx");
        }
    }
    private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
    {
        bool boolReturnValue = false;
        String strConnection = "server=.;database=keshe2;Integrated Security=SSPI";
        SqlConnection connection = new SqlConnection(strConnection);
        connection.Open();
        String strSQL = "Select * From 客户";
        SqlCommand command = new SqlCommand(strSQL, connection);
        SqlDataReader Dr = command.ExecuteReader();
        try {
            while (Dr.Read()){
                if ((UserName == Dr["客户名"].ToString()) & (Password == Dr["密码"].ToString()))
                {
                    int id = Convert.ToInt32(Dr["客户编号"]);
                    Session["id"] = id;
                    Session["name"] = Dr["客户名"].ToString();
                    boolReturnValue = true;
                }
            }
        }catch (SqlException ex) { 
            Response.Write(ex.Message.ToString()); 
        }
        finally{ 
           Dr.Close(); 
        }
        return boolReturnValue;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

    }

    protected void zhuce_Click(object sender, EventArgs e)
    {
        Response.Redirect("Register.aspx");
    }

    protected void LoginButton_Click(object sender, EventArgs e)
    {

    }
}